package de.baumann.browser.activitys.hash

import android.content.Context
import android.content.Intent
import android.text.TextUtils
import android.widget.Button
import android.widget.ImageView
import de.baumann.browser.OdinGlideModule
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.IRechargeView
import de.baumann.browser.present.RechargePresenter
import de.baumann.browser.tasks.SaveImageTaask
import de.baumann.browser.utils.StringUtil
import de.baumann.browser.utils.getUser
import de.baumann.browser.views.widget.JustifyTextView
import de.baumann.browser.views.dialog.RechargeWarnDialog
import kotlinx.android.synthetic.main.activity_recharge.*
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 *@author:
 *@date:2018/12/27 11:18
 *@discription: 充值页面
 */
@Deprecated("废弃")
class RechargeActivity : BaseOdinActivity<IRechargeView,RechargePresenter>(), IRechargeView {

    companion object{
        fun startRechargeActivity(context: Context){
            context.startActivity(Intent(context,RechargeActivity::class.java))
        }
    }

    lateinit var url: String
    override fun getTitleText(): String {
        return getString(R.string.recharge)
    }

    override fun getLayout(): Int {
        return R.layout.activity_recharge
    }

    override fun initView() {
        initToolbar(commToolBar,commTitle)

        findViewById<ImageView>(R.id.ivRechargeQrcode).setOnLongClickListener {
//            GetImageCacheAsyncTask(mContext).execute(url)
            SaveImageTaask(mContext).execute(url)
            true
        }

        findViewById<Button>(R.id.btnCopyUrl).setOnClickListener {
            StringUtil.copy(mContext, ivRechargeAddress.text.toString().trim())
            showShortToast(getString(R.string.Copied))
        }

        findViewById<JustifyTextView>(R.id.tvRechargetip).text = String.format(resources.getString(R.string.rechargetip), getUser()?.service_qq)
    }

    override fun createPresenter(): RechargePresenter {
        return RechargePresenter()
    }

    override fun createView(): IRechargeView {
        return this
    }

    override fun initData() {
        presenter.getRechargeAddress()
    }

    override fun onResume() {
        super.onResume()
        val user = getUser()
        if (user == null || TextUtils.isEmpty(user.eth_address)) {
            notEthUrl()
            return
        }
        RechargeWarnDialog(mContext).show()
    }


    override fun setRechargeQrcode(url: String) {
        this.url = url
        OdinGlideModule.load(mContext, url, findViewById(R.id.ivRechargeQrcode), R.drawable.shape_default_cover)
    }

    override fun setRechargeAddress(url: String) {
        ivRechargeAddress.text = url
    }
}
